<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>GO机网管理后台</title>
		<meta http-equiv="X-UA-Compatible" content="chrome=1,IE=edge">
		<link href="../../css/bootstrap.min.css" rel="stylesheet">
		<link href="css/nifty.min.css" rel="stylesheet">
		<link href="../../css/demo/nifty-demo-icons.min.css" rel="stylesheet">
		<link href="../../plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
		<link href="../../plugins/pace/pace.min.css" rel="stylesheet">
		<script src="../../plugins/pace/pace.min.js?2016/8/5"></script>
		<script src="../../js/jquery-2.2.1.min.js"></script>
		<style>
			#table p {
				padding: 5px;
				margin: 0;
				color: #757575;
			}
			
			td {
				vertical-align: middle!important;
			}
			
			.panel.active {
				border-color: #2ac845;
			}
		</style>
	</head>

	<body id="main">
		<div id="container" class="effect mainnav-lg">
			@@include('public/header.html')
			<div class="boxed">
				<div id="content-container">
					<div id="page-title">
						<h1 class="page-header text-overflow">到店订单管理</h1></div>
					<div id="page-content">
						<div id="page-wrapper">
							<div class="col-sm-8">
								<div class="btn-group" id="btn">
									<button type="button" class="btn btn-default active" name="0">全部</button>
									<button type="button" class="btn btn-default" name="1">待处理</button>
									<button type="button" class="btn btn-default" name="2">待接单</button>
									<button type="button" class="btn btn-default" name="3">待维修</button>
									<button type="button" class="btn btn-default" name="4">待付款</button>
									<button type="button" class="btn btn-default" name="5">待评价</button>
									<button type="button" class="btn btn-default" name="6">已完成</button>
								</div>
							</div>
							<div class="col-sm-4 text-right"><button class="btn btn-primary" v-on:click="prev()" v-show="page>1">上一页</button><button class="btn btn-primary" v-on:click="next()">下一页</button></div>
						</div>
						<div class="col-sm-12 pad-btm pad-top">
							<table class="table table-striped" id="table">
								<tr v-for="list in order_list">
									<td style="width: 30%">
										<div>
											<p>订单状态：{{list.status | getStatus}}</p>
											<p>订单编号：{{list.order_num}}</p>
											<p>下单时间：{{list.ctime | getLocalTime}}</p>
											<p>订单金额：{{list.price}}元</p>
											<p>订单留言：{{list.message}}</p>
										</div>
									</td>
									<td style="width: 25%">
										<div>
											<p>客户姓名：{{list.uname}}</p>
											<p>手机号码：{{list.phone}}</p>
											<p><span v-show="list.admin_info.admin_name">店<span style="visibility: hidden">地区</span>名：</span>{{list.admin_info.admin_name}}</p>
											<p><span v-show="list.admin_info.admin_name">店手机号：</span>{{list.admin_info.phone}}</p>
										</div>
									</td>
									<td style="width: 20%">
										<div class="text-center">
											<p>机型：{{list.phone_name}} （{{list.color}}，{{list.version}}）</p><span class="badge badge-dark pad-all" v-for="li in list.data.fault_info">{{li.name}}</span>
											<p v-if="list.admin_message">加价原因：<span v-text="list.admin_message"></span></p>
										</div>
									</td>
									<td style="width:10%;position:relative;">
										<span class="price">￥{{list.cost_price}}</span>&nbsp;&nbsp;&nbsp;
										<a href="#" v-on:click="editCost(list)">修改</a>
										<input v-if="list.edit" type="number" v-model="list.temp_cost" style="padding: 5px;width: 80px;position: absolute;top: 0;left: 0; bottom: 0; height: 30px;margin: auto;" v-on:blur="changeCostPrice(list);">
									</td>
									<td style="width: 15%" class="text-center"><button class="btn btn-primary" v-on:click="cancel_order(list.order_id)" v-show="list.status<5">取消订单</button></td>
								</tr>
								<tr v-if="order_list.length==0">
									<td colspan="4" class="text-center">暂无数据</td>
								</tr>
							</table>
						</div>
					</div>
				</div>
				 <nav id="mainnav-container">
		            @@include('public/left_menu.html')
		        </nav>
			</div>
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog modal-lg">
					<div class="modal-content">
						<div class="modal-header"><button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
							<h4 class="modal-title" id="myModalLabel">选择师傅</h4></div>
						<div class="modal-body" style="float: left;clear: both;width: 100%">
							<div class="col-sm-4 " v-for="list in master.list">
								<div class="panel panel-bordered pointer master-list" v-on:click="getMasterId(list.admin_id)">
									<div class="panel-body">
										<h4 class="text-center text-info" v-text="list.name"></h4>
										<h3 class="text-center" v-text="list.address"></h3>
										<p class="mar-top"><span class="col-sm-5 text-right">手机号：</span><span class="text-left" v-text="list.phone"></span></p>
									</div>
								</div>
							</div>
						</div>
						<div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button><button type="button" class="btn btn-primary" id="send">指派</button></div>
					</div>
				</div>
			</div>
		</div>
		@@include('public/footer.html')
		<script src="../../js/base.js"></script>
		<script>
			function showId(t, e) {
				var a = {};
				loading.show(), t && (a.status = t), a.page = page, a.count = 10, a.fault_type = 2, $.post("../../index/admin.php?m=Admin&c=Order&a=getOrderList", a, function(a) {
					loading.close(), 200 == a.code ? (2 != e && (monitoring_id && 1 == t && monitoring_id != a.data[0].order_id && (document.getElementById("bofang").play(), alert("订单有变动，请查看")), monitoring_id = a.data[0].order_id), vue.getOrderList(a.data)) : 201 == a.code ? (monitoring_id = -1, page >= 2 ? (alert("没有更多数据"), vue.page--, page--) : vue.getOrderList("")) : 0 == a.code && (location.href = "admin_login.html")
				}, "json")
			}

			function getUTCTime(t) {
				var e = new Date;
				return e.setTime(1e3 * t), e.Format("yyyy-MM-dd hh:mm")
			}

			function getStatus(t) {
				var e = "";
				switch(parseInt(t)) {
					case 1:
						e = "已下单";
						break;
					case 2:
						e = "待接单";
						break;
					case 3:
						e = "待维修";
						break;
					case 4:
						e = "待付款";
						break;
					case 5:
						e = "待评价";
						break;
					case 6:
						e = "已完成"
				}
				return e
			}
			var order_id, admin_id, status = 0,
				page = 1,
				reflash = 3e4,
				monitoring_id;
			var vue = new Vue({
				el: "#main",
				data: {
					master: "",
					order_list: "",
					page: 1
				},
				methods: {
					editCost:function(order){
						order.edit = true;
					},
					changeCostPrice:function(order){
						loading.show();
						$.post(apiNewRepair+"admin.php?m=Admin&c=Order&a=setCostPrice", {
							order_id:order.order_id,
							costPrice:order.temp_cost
						}, function(data){
							order.edit = false;
							loading.close();

							if(data.code>0){
								order.cost_price = order.temp_cost;
								order.temp_cost = order.cost_price;
							} else {
								alert(data.message);
							}
						}, "json")
					},
					getOrderList: function(t) {
						if(t){
							t.forEach(function(x){
								x.edit = false;
								x.temp_cost = x.cost_price;
							});
						}
						this.order_list = t
					},
					appoint: function(t) {
						order_id = t
					},
					getMasterId: function(t) {
						admin_id = t
					},
					prev: function() {
						page >= 2 && (page--, this.page--, showId(status))
					},
					next: function() {
						page++, this.page++, showId(status)
					},
					cancel_order: function(t) {
						var e = {};
						e.order_id = t, bootbox.confirm("是否取消此订单?", function(t) {
							t && $.post("../../index/admin.php?m=Admin&c=Order&a=AdminDelOrder", e, function(t) {
								200 == t.code ? showId(status) : alert(t.message)
							}, "json")
						})
					}
				},
				ready: function() {}
			});
			$("#btn button").click(function() {
				$("#btn button").removeClass("active"), $(this).addClass("active"), page = 1, vue.page = 1, status = $(this).attr("name"), showId(status, 2)
			}), showId(1), Date.prototype.Format = function(t) {
				var e = {
					"M+": this.getMonth() + 1,
					"d+": this.getDate(),
					"h+": this.getHours(),
					"m+": this.getMinutes(),
					"s+": this.getSeconds(),
					"q+": Math.floor((this.getMonth() + 3) / 3),
					"S+": this.getMilliseconds()
				};
				/(y+)/i.test(t) && (t = t.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)));
				for(var a in e) new RegExp("(" + a + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? e[a] : ("00" + e[a]).substr(("" + e[a]).length)));
				return t
			}, Vue.filter("getLocalTime", function(t) {
				return getUTCTime(t)
			}), Vue.filter("getStatus", function(t) {
				return getStatus(t)
			});
		</script>
	</body>
</html>